import  StreamControllerInstance  from '@/utils/stream'
const API_URL = 'http://192.168.110.41:9001/'
const chat = 'ai_chat/chat_stream'

export const newSteam = (params:string,onmessage:any,onerror:any) => {
  console.log(API_URL + chat);
  
  StreamControllerInstance.start({
    url: API_URL + chat,
    data: params,
    onmessage:(event) => {
      if(onmessage){
        return onmessage(event)
      }
    },
    onerror:(err) => {
      if(onerror){
        return onerror(err)
      }
    }
  })
}
export const setabort = () => {
  StreamControllerInstance.abort()
}

export default Object.assign({
  newSteam,
  setabort,
})
